#include<bits/c++.h>
using namespace std;

int a[200005],b[1000005];

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t,n,ans=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        for(int j=0;j<n;j++)
        {
            cin>>a[j];
            b[a[j]]++;
            if(b[a[j]]>1)
                ans+=a[j],b[a[j]]--;
        }
        cout<<ans<<endl;
    }
    return 0;
}
